define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
          // 初始化表格参数配置
          Table.api.init({
            extend: {
                    index_url: 'wadviser/adviser/index',
                    add_url: 'wadviser/adviser/add',
                    edit_url: 'wadviser/adviser/edit',
                    del_url: 'wadviser/adviser/del',
                    multi_url: 'wadviser/adviser/multi',
                    table: 'adviser',
                }
            });

            var table = $('#table');
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [{
                        checkbox: true
                    },
                    {
                        field: 'id',
                        title: __('Id'),
                        operate: false
                    },
                    {
                        field: 'title',
                        title: __('标题'),
                    },
                    {
                        field: 'image',
                        title: __('缩略图'),
                        operate: false,
                        events: Table.api.events.image,
                        formatter: Table.api.formatter.image
                    },
                    {
                        field: 'type',
                        title: __('类型'),
                        searchList: {"1":__('战术实战'),"2":__('战役实战'),"3":__('战略实战')},
                        formatter: Table.api.formatter.label
                    },
                    {
                        field: 'price',
                        title: __('价格'),
                        operate: false
                    },
                    {
                        field: 'after_time',
                        title: __('报名截止'),
                        operate:false,
                        addclass: 'datetimerange',
                        formatter: Table.api.formatter.datetime
                    },
                    {
                        field: 'start_time',
                        title: __('开始时间'),
                        operate: 'RANGE',
                        addclass: 'datetimerange',
                        formatter: Table.api.formatter.datetime
                    },
                    {
                        field: 'end_time',
                        title: __('结束时间'),
                        operate:false,
                        formatter: Table.api.formatter.datetime
                    },
                    {
                        field: 'buttons',
                        width: "120px",
                        title: __('其他操作'),
                        operate:false,
                        table: table,
                        events: Table.api.events.operate,
                        buttons: [
                            {
                                name: 'guide',
                                text: __('手册'),
                                title: __('实战手册'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                extend:'data-area=\'["100%", "100%"]\'',
                                url: function(row){
                                    return 'wadviser/guide/index?adviser_id='+row.id;
                                },
                                visible: function (row) {
                                    //返回true时按钮显示,返回false隐藏
                                    return true;
                                }
                            },
                            {
                                name: 'type',
                                text: __('实战阶段'),
                                title: __('实战图阶段'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                extend:'data-area=\'["100%", "100%"]\'',
                                url: function(row){
                                    return 'wadviser/articletype/index?adviser_id='+row.id;
                                },
                                visible: function (row) {
                                    //返回true时按钮显示,返回false隐藏
                                    return true;
                                }
                            },
                            {
                                name: 'article',
                                text: __('实战图'),
                                title: __('实战图列表'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                extend:'data-area=\'["100%", "100%"]\'',
                                url: function(row){
                                    return 'wadviser/article/index?adviser_id='+row.id;
                                },
                                visible: function (row) {
                                    //返回true时按钮显示,返回false隐藏
                                    return true;
                                }
                            },
                            {
                                name: 'template',
                                text: __('日志模板'),
                                title: __('日志模板设置'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                extend:'data-area=\'["100%", "100%"]\'',
                                url: function(row){
                                    return 'wadviser/config/index?adviser_id='+row.id;
                                },
                                visible: function (row) {
                                    //返回true时按钮显示,返回false隐藏
                                    return true;
                                }
                            },
                            {
                                name: 'baoming',
                                text: __('报名'),
                                title: __('报名列表'),
                                classname: 'btn btn-xs btn-primary btn-dialog',
                                icon: 'fa fa-list',
                                extend:'data-area=\'["100%", "100%"]\'',
                                url: function(row){
                                    return 'wadviser/order/index?adviser_id='+row.id;
                                },
                                visible: function (row) {
                                    //返回true时按钮显示,返回false隐藏
                                    return true;
                                }
                            }
                        ],
                        formatter: Table.api.formatter.buttons
                    },
                    {
                        field: 'operate',
                        title: __('Operate'),
                        table: table,
                        events: Table.api.events.operate,
                        formatter: Table.api.formatter.operate
                    }]
                ]
            });

            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($('form[role=form]'));
            }
        }
    };
    return Controller;
});